///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package company.folder.beans;
//
//import abstractClasses.AbstractEntityList;
//import facades.CompanyFolderFacade;
//import entities.Company;
//import entities.CompanyFolder;
//import javax.inject.Named;
//import java.io.Serializable;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.Locale;
//import java.util.ResourceBundle;
//import javax.enterprise.context.SessionScoped;
//import javax.enterprise.event.Event;
//import javax.enterprise.event.Observes;
//import javax.faces.context.FacesContext;
//import javax.inject.Inject;
//import company.folder.qualifiers.SeeAllProfilesEvent;
//import company.search.qualifiers.RecruitEvent;
//import entities.CompanyAdquiredProfile;
//import entities.CompanyAdquiredProfileFolder;
//import entities.Search;
//import facades.CompanyFolderTypeFacade;
//import java.util.Collections;
//import java.util.List;
//import javax.annotation.PostConstruct;
//import qualifiers.CreatedEntityEvent;
//import qualifiers.LoggedIn;
//import qualifiers.PreCreateEntityEvent;
//
///**
// *
// * @author damfercer
// */
//@Named
//@SessionScoped
//public class FolderListBean extends AbstractEntityList<CompanyFolder, CompanyFolderFacade> implements Serializable {
////    @Inject
////    CompanyFolderFacade folderFacade;
//    @Inject
//    @LoggedIn
//    private Company company;
//    private CompanyFolder newFolder;
//    @Inject
//    private CompanyFolderTypeFacade companyFolderTypeFacade;
////    @Inject
////    @ChosenEntityEvent
////    private Event<CompanyFolder> selectedFolderEvent;
//    @Inject
//    private CompanyFolderFacade companyFolderFacade;
//    @Inject
//    @SeeAllProfilesEvent
//    private Event<Integer> viewAllProfilesEvent;
//    @Inject
//    @PreCreateEntityEvent
//    private Event<CompanyFolder> precreateCompanyFolder;
//    @Inject
//    @CreatedEntityEvent
//    private Event<CompanyFolder> createdCompanyFolder;
////    private CompanyFolder selectedFolder;
//    /**
//     * Creates a new instance of FolderListBean
//     */
//    public FolderListBean() {    
//        if(newFolder==null){
//            newFolder=new CompanyFolder();
//        }
//    }
//    
//    @Override
//    @PostConstruct
//    public void init(){
//        setEntityFacade(getEntityFacadeInstance().get());
//        if(getEntityFacade().findFolderWorkWithUs(company.getIdCompany())!=null){
//            getEntityFacade().evict(getEntityFacade().findFolderWorkWithUs(company.getIdCompany()), (getEntityFacade().findFolderWorkWithUs(company.getIdCompany()).getIdCompanyFolder()));
//        }
//        if(company.getCompanyFolderList()==null){
//            company.setCompanyFolderList(new ArrayList<CompanyFolder>());
//        }
//        setEntityList(company.getCompanyFolderList());
//    }
//    
//    public void editFolderName(CompanyFolder folder){
//        getEntityFacade().edit(folder);
////        List<CompanyAdquiredProfileFolder> list=folder.getCompanyAdquiredProfileFolderList();
////        folder.setCompanyAdquiredProfileFolderList(null);
////        getEntityFacade().edit(folder);
////        folder.setCompanyAdquiredProfileFolderList(list);
//    }
//    
//    public String createNewFolder(){
//        newFolder.setCreationDate(new Date());
//        newFolder.setIdCompany(company);
//        newFolder.setCompanyFolderType(companyFolderTypeFacade.getNormalFolderType());
//        getEntityFacade().create(newFolder);
//        if(company.getCompanyFolderList()==null){
//            company.setCompanyFolderList(new ArrayList<CompanyFolder>());
//        }
//        company.getCompanyFolderList().add(newFolder);
//        newFolder=new CompanyFolder();
//        return null;
//    }
//    
//    public void onNewCompany(@Observes @CreatedEntityEvent Company c){
//        if(c.getCompanyFolderList()==null){
//            c.setCompanyFolderList(new ArrayList<CompanyFolder>());
//        }
//        setEntityList(c.getCompanyFolderList());
//        createFolderWorkWithUs(c);
//    }
//    
//    public CompanyFolder createFolderWorkWithUs(Company company){
//        CompanyFolder workWithUs= new CompanyFolder();
//        workWithUs.setCompanyFolderType(companyFolderTypeFacade.getWorkWithUsFolderType());
//        workWithUs.setCreationDate(new Date());
//        //obtenermo el mensaje
//        FacesContext context=FacesContext.getCurrentInstance();
//        Locale locale=context.getViewRoot().getLocale();
//        ResourceBundle rb = ResourceBundle.getBundle("messages", locale);
//        String workWithUsMesage=rb.getString("WorkWithUs");
//        //setteamos el mensaje
//        workWithUs.setDescription(workWithUsMesage);
//        workWithUs.setIdCompany(company);
//        workWithUs.setCompanyAdquiredProfileFolderList(new ArrayList<CompanyAdquiredProfileFolder>());
//        workWithUs.setSearchList(new ArrayList<Search>());
//        precreateCompanyFolder.fire(workWithUs);
//        companyFolderFacade.create(workWithUs);
//        createdCompanyFolder.fire(workWithUs);
//        return workWithUs;
//    }
//    
//    public void onRecruit(@Observes @RecruitEvent CompanyFolder folder){
//        Collections.replaceAll(getEntityList(), folder, folder);
//    }
//    
//    /**
//     * @return the company
//     */
//    public Company getCompany() {
//        return company;
//    }
//
//    /**
//     * @param company the company to set
//     */
//    public void setCompany(Company company) {
//        this.company = company;
//    }
//
//    /**
//     * @return the newFolder
//     */
//    public CompanyFolder getNewFolder() {
//        return newFolder;
//    }
//
//    /**
//     * @param newFolder the newFolder to set
//     */
//    public void setNewFolder(CompanyFolder newFolder) {
//        this.newFolder = newFolder;
//    }
//    
////    public void selectCompanyFolder(CompanyFolder selected){
////         selectedFolder=selected;
////    }
//    
////    public void deleteFolder(){
////        getCompany().getCompanyFolderList().remove(selectedFolder);
////        folderFacade.remove(selectedFolder);
////        selectedFolder=null;
////    }
//    
////    public String viewFolder(){
////        selectedFolderEvent.fire(selectedFolder);
////        selectedFolder=null;
////        return "/views/company/folder/ViewFolderView?faces-redirect=true";
////    }
//    
//    public String viewAllProfiles(){
//        viewAllProfilesEvent.fire(0);
//        setChosenEntity(null);
//        return "/views/company/folder/ViewAllProfilesView?faces-redirect=true";
//    }
//    
//    /**
//     * @return the previewCandidateList
//     */
//    public List<CompanyAdquiredProfile> getPreviewCandidateList() {
//        List<CompanyAdquiredProfile> validCandidates=new ArrayList<CompanyAdquiredProfile>();
//        if(getChosenEntity().getCompanyFolderType().getIdCompanyFolderType()==2){
//            for (CompanyAdquiredProfile companyAdquiredProfile : getChosenEntity().getCompanyAdquiredProfileList()) {
//                if(companyAdquiredProfile.getCandidate().getBirthDay()!=null && companyAdquiredProfile.getCandidate().getBodyFormal()!=null && companyAdquiredProfile.getCandidate().getBustBlackWhite()!=null && companyAdquiredProfile.getCandidate().getBustColor()!=null && companyAdquiredProfile.getCandidate().getName()!=null && companyAdquiredProfile.getCandidate().getLastName()!=null && !validCandidates.contains(companyAdquiredProfile)){
//                    validCandidates.add(companyAdquiredProfile);
//                }
//            }
//        }
//        else{
//            validCandidates=getChosenEntity().getCompanyAdquiredProfileList();
//        }
//        if(validCandidates.size()>6){
//            validCandidates = new ArrayList<CompanyAdquiredProfile>(validCandidates.subList(validCandidates.size()-7, validCandidates.size()-1));
//        }
//        return validCandidates;
//    }
//
////    /**
////     * @return the selectedFolder
////     */
////    public CompanyFolder getSelectedFolder() {
////        return selectedFolder;
////    }
////
////    /**
////     * @param selectedFolder the selectedFolder to set
////     */
////    public void setSelectedFolder(CompanyFolder selectedFolder) {
////        this.selectedFolder = selectedFolder;
////    }
//
//    //@Override
//    public String redirectToViewEntity() {
//        getChosenEntityEvent().fire(getChosenEntity());
//        setChosenEntity(null);
//        return "/views/company/folder/ViewFolderView?faces-redirect=true";    
//    }
//
//}
